/**
 * Created with PyCharm.
 * User: Admin
 * Date: 11/15/12
 * Time: 4:22 PM
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function () {
//    tinyMCE.init({
//        mode : "textareas",
//        plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,nonbreaking,xhtmlxtras,template,advlist,fullpage,wordcount",
//
//        theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,forecolor,backcolor",
//        theme_advanced_buttons2 :  "mybutton,|,tablecontrols,link,unlink,|,hr,removeformat,pastetext,pasteword,cleanup,|,undo,redo,|,image,code",
//        theme_advanced_buttons3 : "",
//        theme_advanced_toolbar_location : "top",
//        theme_advanced_toolbar_align : "left",
//        theme_advanced_statusbar_location : "bottom",
//        convert_urls : false,
//        fullpage_default_doctype: "",
//        cleanup : false
//    });

    $(".content").each(function(){
        $(this).hide();
    });
    $(".readmore").each(function(){
        $(this).click(function(){
            if ($(this).val() == "Đọc thêm"){

                $(this).parent().nextAll(".content").first().show();
                $(this).val("Thu gọn");
            }
            else
            {
                $(this).parent().nextAll(".content").first().hide();
                $(this).val("Đọc thêm");
            }
        }) ;
    });

    $(function() {
        $( "#datepicker" ).datepicker({
            showOn: "button",
            buttonImage: "/linktaichinh/static/images/calendar.gif",
            buttonImageOnly: true
        });
    });

    $(".ui-datepicker-trigger").each(function(){
        $(this).attr("title", "Bấm vào để chọn ngày");
    });

    $.fn.enabelNotification = function () {
        $(".notify-widget-pane").show();
    };

    $.fn.showNotification = function (msg, duration) {
        $("#notify").enabelNotification();
        $("#notify").text(msg);
        $("#notify").fadeIn('fast');
        if (!duration || typeof duration != 'number') duration = 3000;
        $("#notify").data('delay', setTimeout(function () {
                $("#notify").stop(true, true).fadeOut('fast');
            },
            duration));
    };

    $.ajaxSetup({
        beforeSend:function (xhr, settings) {
            function getCookie(name) {
                var cookieValue = null;
                if (document.cookie && document.cookie != "") {
                    var cookies = document.cookie.split(';');
                    for (var i = 0; i < cookies.length; i++) {
                        var cookie = jQuery.trim(cookies[i]);
                        // Does this cookie string begin with the name we want?
                        if (cookie.substring(0, name.length + 1) == (name + '=')) {
                            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                            break;
                        }
                    }
                }
                return cookieValue;
            }

            if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
                // Only send the token to relative URLs i.e. locally.
                xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
            }

        }
    });
});